//
//  GYNewSaleDetailVC.m
//  GYDemo
//
//  Created by Mrzhang on 2018/6/26.
//  Copyright © 2018年 mac. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "GYNewSaleDetailVC.h"

#import "Head.h"
#import "GYMyBuyProductDetailViewModel.h"
#import "GYSaleProductDetailCell.h"
#import "GYSaleDetailBtomView.h"
#import "GYCartView.h"
#import "GYCartViewModel.h"
#import "GYCartVC.h"

#import "GYMakeOrderVC.h"
#import "GYNewCarView.h"
#import "GYPShareView.h"
#import "GYHomeBuyListVC.h"
@interface GYNewSaleDetailVC ()<SDCycleScrollViewDelegate,UIWebViewDelegate>
{
    float titleW;
    NSInteger currentPage;
    float WebHeight;
    NSInteger selectBtn;
    
}
@property(nonatomic,strong)GYMyBuyProductDetailViewModel* detailModel;
@property(nonatomic,strong)GYSaleDetailBtomView* btomView;
@property(nonatomic,strong)GYNewCarView* cartView;
@property(nonatomic,strong)UIView* displayView;
@property(nonatomic,strong)UIWebView* contentWebView;
@property(nonatomic,strong)GYPShareView* shareView;
@end

@implementation GYNewSaleDetailVC
#pragma mark - getter and setter
-(UIWebView *)contentWebView
{
    if (!_contentWebView) {
        _contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(WFCGFloatX(12), 0, ScreenWidth-WFCGFloatX(24),1)];
        _contentWebView.scrollView.showsVerticalScrollIndicator = NO;
        _contentWebView.scrollView.showsHorizontalScrollIndicator = NO;
        _contentWebView.scrollView.scrollEnabled = NO;
        _contentWebView.delegate = self;
        [_contentWebView setScalesPageToFit:NO];
    }
    return _contentWebView;
}
-(GYPShareView *)shareView
{
    if (!_shareView) {
        @WeakSelf;
        _shareView=[[GYPShareView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, ScreenWidth, WFCGFloatY(151))];
        _shareView.backgroundColor=[UIColor whiteColor];
        _shareView.handler = ^(NSInteger type) {
            [selfp missCartView];
        };
    }
    return _shareView;
}
-(UIView *)displayView
{
    if (!_displayView) {
        _displayView=[[UIView alloc] init];
        _displayView.backgroundColor=[UIColor blackColor];
        _displayView.alpha=0.3;
        _displayView.frame=CGRectMake(0, self.view.height+100, self.view.width, self.view.height);
        @WeakSelf;
        [_displayView addTapGestureRecognizerWithDelegate:self Block:^(NSInteger tag) {
            [selfp missCartView];
        }];
    }
    return _displayView;
}
-(GYNewCarView *)cartView
{
    if (!_cartView) {
        _cartView=[[GYNewCarView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT+100, self.view.width, WFCGFloatY(466))];
        _cartView.backgroundColor=[UIColor whiteColor];
        [WFFunctions addCornerToView:_cartView radius:10 corner:UIRectCornerTopLeft|UIRectCornerTopRight];
        @WeakSelf;
        
        _cartView.backHandler = ^(NSInteger type, NSDictionary *dic) {
            if (type==3)
            {
                [selfp missCartView];
            }
            if (1 == type) {

            }
            if (2 == type) {
                if (selectBtn==4)
                {
                    if (2==1)
                    {
                        [FTIndicator showErrorWithMessage:@"商品数量不能低于起订数量!"];
                    }else
                    {
                        NSMutableDictionary* para = [[NSMutableDictionary alloc] init];
                        para[@"saleproid"] = [NSString stringWithFormat:@"%@",selfp.passID];
                        NSString *num = dic[@"num"] ?: @"0";
                        para[@"num"] = [NSString stringWithFormat:@"%@",num];
                        [[GYCartViewModel shareInterface] requestAdd:para];
                        [selfp missCartView];
                    }
                }
                if (selectBtn==5)
                {
                    if (2==1)
                    {
                        [FTIndicator showErrorWithMessage:@"商品数量不能低于起订数量!"];
                    }else
                    {
                        [selfp requestOrder:dic[@"num"]];
                    }
                }
            }
        };
    }
    return _cartView;
}
-(GYSaleDetailBtomView *)btomView
{
    if (!_btomView)
    {
        _btomView=[[GYSaleDetailBtomView alloc] initWithFrame:CGRectMake(0, self.view.height-45-self.bottomShelterHeight, self.view.width, 45)];
        _btomView.backgroundColor=[UIColor whiteColor];
        _btomView.userInteractionEnabled=YES;
        _btomView.passID=_passID;
        @WeakSelf;
        _btomView.btnCallBack = ^(NSInteger type) {
            if ([[GYLoginViewModel shareInterface] roleType]==1)
            {
                if ([[GYLoginViewModel shareInterface] loginstatus])
                {
                    if (type==2)
                    {

                    }
                    if (type==3)
                    {
                        GYCartVC* gy=[[GYCartVC alloc] init];
                        [selfp.navigationController pushViewController:gy animated:YES];
                    }
                    if (type==4||type==5)
                    {
                        selectBtn=type;
                        [selfp showCartView];
                    }
                }else
                {
                    [[GCPresenter shareInterface] loadLogin];
                }
            }else
            {
                [FTIndicator showErrorWithMessage:@"您还不是革优认证会员,请先注册并认证!"];
            }
        };
    }
    return _btomView;
}
-(GYMyBuyProductDetailViewModel *)detailModel
{
    if (!_detailModel) {
        _detailModel=[[GYMyBuyProductDetailViewModel alloc] init];
    }
    return _detailModel;
}
#pragma mark - event
#pragma mark - method
-(void)missCartView
{
    _displayView.frame=CGRectMake(0, SCREEN_HEIGHT+100, self.view.width, SCREEN_HEIGHT);
    [UIView animateWithDuration:0.4 animations:^{
        _cartView.frame=CGRectMake(0, SCREEN_HEIGHT+100, self.view.width, WFCGFloatY(466));
        _shareView.frame=CGRectMake(0, SCREEN_HEIGHT, self.view.width, WFCGFloatY(151));
    }];
}
-(void)showCartView
{
    _displayView.frame=CGRectMake(0, 0, self.view.width, SCREEN_HEIGHT);
    [UIView animateWithDuration:0.4 animations:^{
        _cartView.frame=CGRectMake(0, SCREEN_HEIGHT-WFCGFloatY(466), self.view.width, WFCGFloatY(466));
    }];
}
-(void)showShareView
{
    _displayView.frame=CGRectMake(0, 0, self.view.width, SCREEN_HEIGHT);
    [UIView animateWithDuration:0.4 animations:^{
        _shareView.frame=CGRectMake(0, SCREEN_HEIGHT-WFCGFloatY(151), self.view.width, WFCGFloatY(151));
    }];
}
#pragma mark - life

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.btomView layoutSubviews];
}
-(void)setBarItem
{
    @WeakSelf;
    [self setNavgationTheme:2];
    
    UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBarButton.frame = CGRectMake(0, 0, 30 , 30);
    leftBarButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [leftBarButton setBackgroundImage:[UIImage imageNamed:@"saledetail_back"] forState:UIControlStateNormal];
    [leftBarButton addTarget:self action:@selector(leftBarButtonItemTap) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];
    
    UIButton *rightBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBarButton.frame = CGRectMake(0, 0, 30 , 30);
    rightBarButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [rightBarButton setBackgroundImage:[UIImage imageNamed:@"saledetail_mem"] forState:UIControlStateNormal];
    [rightBarButton addTarget:self action:@selector(gotoMenMu) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButton];

    UIButton *rightBarButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBarButton1.frame = CGRectMake(0, 0, 30, 30);
    rightBarButton1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [rightBarButton1 setBackgroundImage:[UIImage imageNamed:@"saledetail_cart"] forState:UIControlStateNormal];
    [rightBarButton1 handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        GYCartVC* gy=[[GYCartVC alloc] init];
        [selfp.navigationController pushViewController:gy animated:YES];
    }];
    UIBarButtonItem *rItem1 = [[UIBarButtonItem alloc] initWithCustomView:rightBarButton1];
    self.navigationItem.rightBarButtonItems=@[rItem,rItem1];
}
-(void)initilization
{
    titleW=0;
    currentPage=1;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view addSubview:self.baseTable];
    
    if ([[GYLoginViewModel shareInterface] roleType]==1)
    {
        [self.view addSubview:self.btomView];;
        self.baseTable.height = self.view.height -45-self.bottomShelterHeight;
    }else
    {
        self.baseTable.height = self.view.height-self.bottomShelterHeight;
    }
    
    [self.view addSubview:self.displayView];
    [self.view addSubview:self.cartView];
    [self.view addSubview:self.shareView];

    if (@available(iOS 11.0, *)) {
        self.baseTable.contentInset = UIEdgeInsetsMake(-GY_Nav_height, 0, 0, 0);
    }
    self.baseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.baseTable.showsVerticalScrollIndicator=NO;
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [self.baseTable setBackgroundColor:[UIColor whiteColor]];
    self.baseTable.y=-1;
    
    @WeakSelf;
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [selfp reloadData];
        [selfp loadrecord];
    }];
    
    [self viewModelBand];
    [self reloadData];
    [self loadrecord];
}
-(void)viewModelBand
{
    @WeakSelf;
    GCBaseObservationModel *loginOb = [GCBaseObservationModel new];
    loginOb.observation = [GYLoginViewModel shareInterface];
    loginOb.keyPath = @"loginstatus";
    loginOb.handler = ^(NSString *keyPath) {
        [selfp.baseTable reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
    };
    [self registObservation:loginOb];
    
    GCBaseObservationModel *observation0 = [GCBaseObservationModel new];
    observation0.observation = [GYMineShopAddressViewModel shareInterface];
    observation0.keyPath = @"defaultAddress";
    observation0.handler = ^(NSString *keyPath) {
        [_cartView layoutSubviews];
    };
    [self registObservation:observation0];
    
    GCBaseObservationModel *observation = [GCBaseObservationModel new];
    observation.observation = self.detailModel;
    observation.keyPath = @"BuyProductDetailInfoModel";
    observation.handler = ^(NSString *keyPath) {
        [_cartView setViewModel:selfp.detailModel];
        [selfp.baseTable reloadData];
    };
    [self registObservation:observation];
    
    
    GCBaseObservationModel *observation1 = [GCBaseObservationModel new];
    observation1.observation = self.detailModel;
    observation1.keyPath = @"BuyProductUserInfoModel";
    observation1.handler = ^(NSString *keyPath) {
        //刷新section 1
        [selfp.baseTable reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
    };
    [self registObservation:observation1];
    
    GCBaseObservationModel *observation2 = [GCBaseObservationModel new];
    observation2.observation = self.detailModel;
    observation2.keyPath = @"protypeArr";
    observation2.handler = ^(NSString *keyPath) {
        //刷新section 2
        [selfp.baseTable reloadData];
    };
    [self registObservation:observation2];
    
    GCBaseObservationModel *observation3 = [GCBaseObservationModel new];
    observation3.observation = self.detailModel;
    observation3.keyPath = @"RecordArr";
    observation3.handler = ^(NSString *keyPath) {
        [selfp.baseTable reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationNone];
    };
    [self registObservation:observation3];
    
    
    GCBaseObservationModel *observation5 = [GCBaseObservationModel new];
    observation5.observation = [GYCartViewModel shareInterface];
    observation5.keyPath = @"datas";
    observation5.handler = ^(NSString *keyPath) {
        [selfp.btomView layoutSubviews];
    };
    [self registObservation:observation5];
}
-(void)reloadData
{
    NSMutableDictionary* dic=[[NSMutableDictionary alloc] init];
    dic[@"id"]=[NSString stringWithFormat:@"%@",_passID];
    [self.detailModel requestInfo:dic];
}
-(void)loadrecord
{
    NSMutableDictionary* dic=[[NSMutableDictionary alloc] init];
    dic[@"proid"]=[NSString stringWithFormat:@"%@",_passID];
  //  dic[@"page"]=[NSString stringWithFormat:@"%ld",currentPage];
    [self.detailModel requestRecord:dic];
}

#pragma mark - life
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.view.userInteractionEnabled=YES;
    self.isGroup=YES;
    [self initilization];
    [self setBarItem];
}
-(void)leftBarButtonItemTap
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0) {
        return 1;
    }
    if (section==1) {
        return 1;
    }
    if (section==2) {
        return 1;
    }
    return self.detailModel.RecordArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section==0)
    {
        static NSString *CellID = @"Cellbanner";
        GYSaleProductDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[GYSaleProductDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.inforModel=self.detailModel.BuyProductDetailInfoModel;
        cell.passArr=self.detailModel.protypeArr;
        @WeakSelf;
        [cell.shareBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
            [selfp showShareView];
        }];
        return cell;
    }
    
    if (indexPath.section==1)
    {

            static NSString *CellID = @"CellID1";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            [cell.contentView removeAllSubviews];
            
            UIImageView* markIV=[[UIImageView alloc] init];
            markIV.image=[UIImage imageNamed:@"dianpu0"];
            markIV.frame=WFCGRectMake(12, (53-markIV.image.size.height)/2, markIV.image.size.width, markIV.image.size.height);
            [cell.contentView addSubview:markIV];
        
            
            UILabel* nameLab=[[UILabel alloc] init];
            nameLab.frame=WFCGRectMake(35, 16, 200, 21);
            nameLab.textColor=Main_Color_Black;
            nameLab.font=SYSTEMFONT(15);
            nameLab.text=self.detailModel.BuyProductUserInfoModel.companyname;
            [cell.contentView addSubview:nameLab];
            
            NSString* str=self.detailModel.BuyProductUserInfoModel.xlevel;
            
            NSMutableArray * arr = [NSMutableArray arrayWithCapacity:0];
            // 遍历字符串，按字符来遍历。每个字符将通过block参数中的substring传出
            [str enumerateSubstringsInRange:NSMakeRange(0, str.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                [arr addObject:substring];
            }];
            
            for (int i=0; i<[arr count]; i++)
            {
                UIImageView* iv=[[UIImageView alloc] init];
                if ([arr[i] isEqualToString:@"A"])
                {
                    iv.image=[UIImage imageNamed:@"xydj_a"];
                }
                if ([arr[i] isEqualToString:@"B"])
                {
                    iv.image=[UIImage imageNamed:@"xydj_b"];
                }
                iv.frame=WFCGRectMake(375-47-20*i, (53-iv.image.size.height)/2, iv.image.size.width, iv.image.size.height);
                [cell.contentView addSubview:iv];
            }
            return cell;
    
    }
    
    if (indexPath.section==2)
    {
        static NSString *CellID = @"Cell33ID";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
        }
        [cell.contentView removeAllSubviews];
        [cell.contentView addSubview:self.contentWebView];
        [_contentWebView loadHTMLString:self.detailModel.BuyProductDetailInfoModel.descriptionField  baseURL:nil];
        _contentWebView.mj_h=WebHeight;

        
        return cell;
    }
    return [UITableViewCell new];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return WFCGFloatY(139)+ScreenWidth;
    }
    if (indexPath.section==1) {

        return WFCGFloatY(53);
    }
    if (indexPath.section==2) {
        return WebHeight;
    }
    GoodSCommentModel* model =self.detailModel.RecordArr[indexPath.row];
    CGSize temSize=[WFFunctions WFStrGetSize:model.remark width:SCREEN_WIDTH-WFCGFloatX(20) font:SYSTEMFONT(12)];
    return WFCGFloatY(54)+temSize.height+10;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor whiteColor];
    
    if (section==2||section==3)
    {
        UIImageView* markIV=[[UIImageView alloc] init];
        markIV.frame=WFCGRectMake(15, 16.5,5,17);
        markIV.backgroundColor=Main_Color_Red;
        [view addSubview:markIV];
        
        UILabel* nameLab=[[UILabel alloc] init];
        nameLab.frame=WFCGRectMake(30, 0, 200, 50);
        nameLab.textColor=Main_Color_Black;
        nameLab.font=SYSTEMFONT(18);
        [view addSubview:nameLab];

        if (section==2)
        {
            nameLab.text=@"商品介绍";
        }
        if (section==3)
        {
            nameLab.text=@"评价";
        }
    }
    
    return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=Main_Color_BG;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0||section==1) {
        return .00001f;
    }
    return WFCGFloatY(50);
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 7;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==1)
    {
        if ([[GYLoginViewModel shareInterface] roleType]==1)
        {
            if ([[GYLoginViewModel shareInterface] loginstatus])
            {

            }else
            {
                [[GCPresenter shareInterface] loadLogin];
            }
        }else
        {
            [FTIndicator showErrorWithMessage:@"您还不是革优认证会员,请注册并认证~"];
        }
    }
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    CGRect newFrame = webView.frame;
    newFrame.size.height = actualSize.height;
    if (WebHeight == newFrame.size.height) {
        return;
    }
    
    WebHeight = newFrame.size.height;
    [self.baseTable reloadData];
}
-(void)requestOrder:(NSString*)countNum
{
//    NSMutableDictionary* paraDic=[[NSMutableDictionary alloc] init];
//    paraDic[@"num"]=countNum;
//    paraDic[@"proid"]=[NSString stringWithFormat:@"%@",self.detailModel.BuyProductDetailInfoModel.];
//    
//    @WeakSelf;
//    NSString *interface = @"buyMakeOrder";
//    [[InterfaceManager shareInterface]requetInterface:interface withParameter:paraDic handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
//
//        NSDictionary *data = infoModel.data;
//        if ([data isKindOfClass:[NSDictionary class]]) {
//
//            GYMakeOrderVC* gy=[[GYMakeOrderVC alloc] init];
//            gy.model=selfp.detailModel.BuyProductDetailInfoModel;
//            gy.infoModel=selfp.detailModel.BuyProductUserInfoModel;
//            gy.passID=selfp.passID;
//            gy.countNum=countNum;
//            gy.goodData=[[NSMutableDictionary alloc] initWithDictionary:data];
//            [selfp.navigationController pushViewController:gy animated:YES];
//            
//            [selfp missCartView];
//
//        }else
//        {
//            [FTIndicator showErrorWithMessage:[info objectForKey:@"message"]];
//           // [self.navigationController popViewControllerAnimated:YES];
//        }
//    }];
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
